package com.z.controller;

import com.z.pojo.Users;
import com.z.service.UsersService;
import com.z.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/UpdateUServlet")
public class UpdateUServlet extends HttpServlet {
    private UsersService usersService=new UsersServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("text/html; charset=utf-8");
        String uid = req.getParameter("uid");
        String account = req.getParameter("account");
        String uname = req.getParameter("uname");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");
        String gender = req.getParameter("gender");
        String level=req.getParameter("level");
        Users users = new Users(Integer.parseInt(uid), uname,account,password,Integer.parseInt(level),gender,phone);
        Integer integer = usersService.updateUsersByuid(users);
        System.out.println(integer);
        if(integer > 0)
        {
            req.setAttribute("msg","修改成功");
        }else
        {
            req.setAttribute("msg","修改失败");
        }
        req.getRequestDispatcher("/manageUser").forward(req,resp);

    }
}
